import { defHttp } from '/@/utils/http/axios';
import {
  MessageListGetResultModel,
  MessageModel,
  MessagePageListGetResultModel,
  MessageParams,
  MessagePageSearchParams,
  MessageListSearchParams,
  UpdateMessageParams,
  MessageIDType,
} from '/@/api/opms/model/MessageModel';

import { UploadFileParams } from '/#/axios';
import { useGlobSetting } from '/@/hooks/setting';
import { UploadApiResult } from '../sys/model/uploadModel';

// 消息通知接口
export enum Api {
  PublicApi = '/opms/message',
  ListApi = `/opms/message/list`,
  PageApi = `/opms/message/page`,
  BatchApi = `/opms/message/batch`,
  ExportApi = `/opms/message/export`,
  ImportApi = `/opms/message/import`,
}
/**
 * @description:  获取列表
 * @param params
 * @returns
 */
export const getMessageList = (params?: MessageListSearchParams) =>
  defHttp.get<MessageListGetResultModel>({ url: Api.ListApi, params });

/**
 * @description:  分页获取列表
 * @param params
 * @returns
 */
export const getMessagePage = (params: MessagePageSearchParams) =>
  defHttp.get<MessagePageListGetResultModel>({ url: Api.PageApi, params });

/**
 * @description:  根据id获取
 * @param id
 * @returns
 */
export const getMessage = (id: MessageIDType) =>
  defHttp.get<MessageModel>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  创建
 * @param params
 * @returns
 */
export const createMessage = (params: MessageParams) =>
  defHttp.post<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  更新
 * @param params
 * @returns
 */
export const updateMessage = (params: UpdateMessageParams) =>
  defHttp.put<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  物理删除
 * @param id
 * @returns
 */
export const deleteMessage = (id: MessageIDType) =>
  defHttp.delete<boolean>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  物理批量删除
 * @param ids
 * @returns
 */
export const deleteMessageBatch = (ids: MessageIDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
 * @description:  逻辑删除
 * @param ids
 * @returns
 */
export const logicDeleteMessage = (id: MessageIDType) =>
  defHttp.delete<boolean>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  逻辑批量删除
 * @param ids
 * @returns
 */
export const logicDeleteMessageBatch = (ids: MessageIDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
 * @description:  导出文件
 * @param ids
 * @returns
 */
export const exportMessageListFile = (ids: MessageIDType[]) =>
  defHttp.post<boolean>({ url: Api.ExportApi, params: { ids } });

/**
 * @description:  导入文件
 * @param ids
 * @returns
 */
export const importMessageListFile = (
  params: UploadFileParams,
  onUploadProgress?: (progressEvent: ProgressEvent) => void,
) =>
  defHttp.uploadFile<UploadApiResult>(
    {
      url: useGlobSetting().apiUrl + Api.ImportApi,
      onUploadProgress,
    },
    params,
  );
